<?php
namespace App\Http\Controllers\AppApi\Home;

use App\Services\Main\AdService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;

class AdController extends BaseController
{
    /**
     * 广告
     * 制作者：九哥
     */

    protected $service;

    public function __construct()
    {
        parent::__construct();
        $this->service = new AdService();
    }

    /**
     * /api/home/ad
    */
    public function index(Request $request)
    {

        if ($request->app_access!=$this->app_access) {
            return $this->toJson(-1);
        }
//        $token = $request->token;
        $genre = $request->genre;
//        if (!$token) { return $this->toJson(-2); }
//        $uid = $this->accessGet($token);
//        if (!$uid) { return $this->toJson(-13); }
        if (!$genre) { return $this->toJson(-2); }

        $dataArr = Cache::remember('/api/home/ad'.$genre, 10000,
            function()use ($genre) {

            return ['banner'=>$this->service->getAppIndex($genre)];
        });



        if (!$dataArr) { return $this->toJson(-3); }
        return $this->toJson(0,$dataArr);
    }
}